home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / FFT / FFTR2E.ASM < prev    next >
Assembly Source File  |  1990-01-17  |  9KB  |  207 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; 1024-Point, 3.39ms Non-In-Place FFT. 
  6. ; Last Update 04 Feb 87   Version 1.0
  7. ;
  8. fftr2e  macro   data,coef
  9. fftr2e  ident   1,0
  10. ;
  11. ; 1024 Point Complex Fast Fourier Transform Routine
  12. ;
  13. ; This routine performs a 1024 point complex FFT on external data
  14. ; using the Radix 2, Decimation in Time, Cooley-Tukey FFT algorithm.
  15. ;
  16. ;    Complex input and output data
  17. ;        Real data in X memory
  18. ;        Imaginary data in Y memory
  19. ;    Normally ordered input data
  20. ;    Bit reversed output data
  21. ;       Coefficient lookup table
  22. ;        -Cosine values in X memory
  23. ;        -Sine values in Y memory
  24. ;
  25. ; Macro Call - fftr2e   data,coef
  26. ;
  27. ;       data       start of external data buffer
  28. ;       coef       start of sine/cosine table
  29. ;
  30. ; Radix 2, Decimation In Time Cooley-Tukey FFT algorithm
  31. ;             ___________
  32. ;            |           | 
  33. ; ar,ai ---->|  Radix 2  |----> ar',ai'
  34. ; br,bi ---->| Butterfly |----> br',bi'
  35. ;            |___________|
  36. ;                  ^
  37. ;                  |
  38. ;                wr,wi
  39. ;
  40. ;       ar' = ar + wr*br - wi*bi
  41. ;       ai' = ai + wi*br + wr*bi
  42. ;       br' = ar - wr*br + wi*bi = 2*ar - ar'
  43. ;       bi' = ai - wi*br - wr*bi = 2*ai - ai'
  44. ;
  45. ; Address pointers are organized as follows:
  46. ;
  47. ;  r0 = ar,ai input pointer     n0 = group offset       m0 = modulo (points)
  48. ;  r1 = br,bi input pointer     n1 = group offset       m1 = modulo (points)
  49. ;  r2 = ext. data base address  n2 = groups per pass    m2 = 256 pt fft counter
  50. ;  r3 = coef. offset each pass  n3 = coefficient base addr.     m3 = linear
  51. ;  r4 = ar',ai' output pointer  n4 = group offset       m4 = modulo (points)
  52. ;  r5 = br',bi' output pointer  n5 = group offset       m5 = modulo (points)
  53. ;  r6 = wr,wi input pointer     n6 = coef. offset       m6 = bit reversed
  54. ;  r7 = not used (*)            n7 = not used (*)       m7 = not used (*)
  55. ;
  56. ;       * - r7, n7 and m7 are typically reserved for a user stack pointer.
  57. ;
  58. ; Alters Data ALU Registers
  59. ;       x1      x0      y1      y0
  60. ;       a2      a1      a0      a
  61. ;       b2      b1      b0      b
  62. ;
  63. ; Alters Address Registers
  64. ;       r0      n0      m0
  65. ;       r1      n1      m1
  66. ;       r2      n2      m2
  67. ;       r3      n3      m3
  68. ;       r4      n4      m4
  69. ;       r5      n5      m5
  70. ;       r6      n6      m6
  71. ;
  72. ; Alters Program Control Registers
  73. ;       pc      sr
  74. ;
  75. ; Uses 8 locations on System Stack                                           
  76. ;
  77. ; Latest Revision - 4-Feb-87
  78. ;
  79. _points equ     1024            ;number of FFT points
  80. _intdata        equ     0       ;address of internal data workspace
  81.         move    #data,r2        ;initialize input pointers
  82.         move    r2,r0
  83.         move    #_points/4,n0   ;initialize butterflies per group
  84.         move    n0,n4           ;initialize pointer offsets
  85.         move    n0,n6           ;initialize coefficient offset
  86.         move    #coef,n3        ;initialize coefficient base address
  87.         move    #_points-1,m0   ;initialize address modifiers
  88.         move    m0,m1           ;for modulo(points) addressing
  89.         move    m0,m4
  90.         move    m0,m5
  91.         move    #-1,m3          ;linear addressing for coefficient base offset
  92.         move    #0,m2           ;initialize 256 point fft counter
  93.         move    m2,m6           ;initialize coefficient address modifier
  94.                                 ;for reverse carry (bit reversed) addressing
  95. ;
  96. ; Do first and second Radix 2 FFT passes
  97. ;
  98.         move            x:(r0)+n0,x0
  99.         tfr     x0,a    x:(r0)+n0,y1
  100.  
  101.         do      n0,_twopass
  102.         tfr     y1,b    x:(r0)+n0,y0
  103.         add     y0,a    x:(r0),x1                       ;ar+cr
  104.         add     x1,b    r0,r4                           ;br+dr
  105.         add     a,b     (r0)+n0                         ;ar'=(ar+cr)+(br+dr)
  106.         subl    b,a     b,x:(r0)+n0                     ;br'=(ar+cr)-(br+dr)
  107.         tfr     x0,a    a,x0            y:(r0),b
  108.         sub     y0,a                    y:(r4)+n4,y0    ;ar-cr
  109.         sub     y0,b    x0,x:(r0)                       ;bi-di
  110.         add     a,b                     y:(r0)+n0,x0    ;cr'=(ar-cr)+(bi-di)
  111.         subl    b,a     b,x:(r0)                        ;dr'=(ar-cr)-(bi-di)
  112.         tfr     x0,a    a,x0            y:(r4),b
  113.         add     y0,a                    y:(r0)+n0,y0    ;bi+di
  114.         add     y0,b    x0,x:(r0)+n0                    ;ai+ci
  115.         add     b,a                     y:(r0)+,x0      ;ai'=(ai+ci)+(bi+di)
  116.         subl    a,b                     a,y:(r4)+n4     ;bi'=(ai+ci)-(bi+di)
  117.         tfr     x0,a                    b,y:(r4)+n4
  118.         sub     y0,a    x1,b                            ;ai-ci
  119.         sub     y1,b    x:(r0)+n0,x0                    ;dr-br
  120.         add     a,b     x:(r0)+n0,y1                    ;ci'=(ai-ci)+(dr-br)
  121.         subl    b,a                     b,y:(r4)+n4     ;di'=(ai-ci)-(dr-br)
  122.         tfr     x0,a                    a,y:(r4)+
  123. _twopass
  124. ;                                                                   
  125. ; Do remaining 8 FFT passes as four 256 point Radix 2 FFT's using internal data
  126. ; and external coefficients.
  127. ;
  128. ; Each 256 point Radix 2 FFT consists of 8 passes.  The first pass uses external
  129. ; input data and internal output data to move the data on-chip.  Intermediate
  130. ; passes use internal input data and internal output data to keep the data
  131. ; on-chip.  The last pass uses internal input data and external output data
  132. ; to move the data off-chip.
  133. ;
  134.         do      #4,_end_fft     ;do 256 point fft four times
  135.         move    r2,r0           ;get external data input address for first pass
  136.         move    m2,r3           ;update coefficient offset
  137.         move    #256/2,n0       ;initialize butterflies per group
  138.         move    #1,n2           ;initialize groups per pass
  139.  
  140.         do      #7,_end_pass    ;do first 7 passes out of 8
  141.         move    #_intdata,r4    ;initialize A output pointer
  142.         move    n0,n1           ;initialize pointer offsets
  143.         move    n0,n4
  144.         move    n0,n5
  145.         lua     (r0)+n0,r1      ;initialize B input pointer
  146.         lua     (r4)+n4,r5      ;initialize B output pointer
  147.         lua     (r3)+n3,r6      ;initialize W input pointer
  148.         move    (r5)-
  149.  
  150.         do      n2,_end_grp
  151.         move    x:(r1),x1       y:(r6),y0       ;lookup -sine value
  152.         move    x:(r5),a        y:(r0),b
  153.         move    x:(r6)+n6,x0            ;lookup -cosine value
  154.  
  155.                                                  
  156.         do      n0,_end_bfy     ;Radix 2 DIT butterfly kernel with constant
  157.         mac     x1,y0,b                         y:(r1)+,y1   ;twiddle factor
  158.         macr    -x0,y1,b        a,x:(r5)+       y:(r0),a
  159.         subl    b,a             x:(r0),b        b,y:(r4)
  160.         mac     -x1,x0,b        x:(r0)+,a       a,y:(r5)
  161.         macr    -y1,y0,b        x:(r1),x1
  162.         subl    b,a             b,x:(r4)+       y:(r0),b
  163. _end_bfy
  164.         move    a,x:(r5)+n5     y:(r1)+n1,y1    ;dummy load of x1 and y1
  165.         move    x:(r0)+n0,x1    y:(r4)+n4,y1
  166. _end_grp
  167.         move    n0,b1
  168.         lsr     b       n2,a1   ;divide butterflies per group by two
  169.         lsl     a       b1,n0   ;multiply groups per pass by two
  170.         move            r3,b1
  171.         lsr     b       a1,n2   ;divide coefficient offset by two
  172.         move            b1,r3
  173.         move            #_intdata,r0    ;intermediate passes use internal input data
  174. _end_pass
  175. ;        
  176. ; Do last FFT pass and move output data off-chip to external data memory.
  177. ;
  178.         move    n1,n0           ;correct pointer offset for last pass
  179.         move    r2,r4           ;initialize A output pointer
  180.         lua     (r0)+,r1        ;initialize B input pointer
  181.         lua     (r4)-n4,r5      ;initialize B output pointer
  182.         lua     (r3)+n3,r6      ;initialize W input pointer
  183.         move    (r5)+
  184.         move    x:(r1),x1       y:(r6),y0
  185.